<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <link href="{{ url_for('static',filename='js/plupload-2.1.2/js/jquery.ui.plupload/css/jquery.ui.plupload.css') }}"
          rel="stylesheet" type="text/css">
    <link href="{{ url_for('static',filename='js/plupload-2.1.2/js/jquery.plupload.queue/css/jquery.plupload.queue.css') }}"
          rel="stylesheet" type="text/css">


    <title>Plupload - Getting Started</title>

    <script type="text/javascript"
            src="{{ url_for('static', filename='js/plupload-2.1.2/js/plupload.full.min.js') }}"></script>
    <script type="text/javascript"
            src="{{ url_for('static', filename='js/plupload-2.1.2/js/jquery.ui.plupload/jquery.ui.plupload.min.js') }}"></script>
    <script type="text/javascript"
            src="{{ url_for('static', filename='js/plupload-2.1.2/js/jquery.plupload.queue/jquery.plupload.queue.min.js') }}"></script>
    <script type="text/javascript"
            src="{{ url_for('static', filename='js/plupload-2.1.2/js/i18n/zh_CN.js') }}"></script>

</head>
<body>

<div id="filelist" name="filelist[]"></div>

<div id="container">
    <a id="pickfiles" class="btn btn-success btn-sm" href="javascript:;">选择文件</a>
    <a id="uploadfiles" href="javascript:;">[Upload files]</a>
</div>

<br/>
<pre id="console"></pre>


<script type="text/javascript">
    // Custom example logic

    var uploader = new plupload.Uploader({
        runtimes: 'html5,flash,silverlight,html4',

        browse_button: 'pickfiles', // you can pass in id...
        container: document.getElementById('container'), // ... or DOM Element itself

        url: "{{ url_for('main.upload') }}",

        filters: {
            max_file_size: '10mb',
            mime_types: [
                {title: "Image files", extensions: "jpg,gif,png"},
                {title: "Zip files", extensions: "zip"}
            ]
        },

        // Flash settings
        flash_swf_url: '{{ url_for('static', filename='js/plupload-2.1.2/js/Moxie.swf')}}',

        // Silverlight settings
        silverlight_xap_url: '{{ url_for('static', filename='js/plupload-2.1.2/js/Moxie.xap')}}',


        init: {
            PostInit: function () {
                document.getElementById('filelist').innerHTML = '';

                document.getElementById('uploadfiles').onclick = function () {
                    uploader.start();
                    return false;
                };
            },

            FilesAdded: function (up, files) {
                plupload.each(files, function (file) {
                    document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
                });
            },

            UploadProgress: function (up, file) {
                document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
            },

            Error: function (up, err) {
                document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
            }
        }
    });

    uploader.init();

</script>

</body>
</html>